package com.xxh.driect;

import com.rabbitmq.client.*;
import com.xxh.utils.MqUtils;

import java.io.IOException;

public class Consumer1 {
    public static void main(String[] args) throws IOException {
        Connection connection = MqUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare("myexchange2","direct");
        //声明临时队列
        String queue = channel.queueDeclare().getQueue();
        /**
         * 1 队列名称
         * 2 交换机名称
         * 3 路由key
         */
        channel.queueBind(queue,"myexchange2","info");

        channel.basicConsume(queue,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("c1收到了消息："+new String(body));
            }
        });
    }
}
